import http from '@/utils/axios.js'

export function login(username, password) {
    return http.post('/login', {username, password})
}

export function logout() {
    return http.post('/logout')
}
//获取所有用户
export const getUsers = async () => {
    return await http.get('/users')
}

//添加用户
export const addUser = async (userData) => {
    // console.log('发送到服务器的数据:', userData)
    try {
        const response = await http.post('/users', userData)
        // console.log('服务器响应:', response)
        return response
    } catch (error) {
        // console.error('添加用户请求错误:', error.response?.data || error.message)
        throw error
    }
}
//更新用户信息
export const updateUser = async (userId, userData) => {
    return await http.put(`/users/${userId}`, userData)
}
// 删除用户
export const deleteUser = async (userId) => {
        return  await http.delete(`/users/${userId}`)
}